#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 110;
int arr[N];
int n;
int main()
{
	cin >> n;
	priority_queue<int, vector<int>, greater<int>>heap;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		heap.push(x);
	}
	int sum = 0;
	while(heap.size() != 1) {
		int a = heap.top();
		heap.pop();
		int b = heap.top();
		heap.pop();
		sum += a * b;
		heap.push(a + b);
	}
	cout << sum << endl;
	return 0;
}